package com.xn.service;

import com.xn.api.StockApi;
import com.xn.mapper.OrderMapper;
import com.xn.model.Order;
import io.seata.spring.annotation.GlobalTransactional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class OrderService {

    @Autowired
    private OrderMapper orderMapper;
    @Autowired
    private StockApi stockApi;

    @GlobalTransactional
    public String createOrder(String flag){

        Order order = new Order();
        order.setName("order01");
        orderMapper.insert(order);
        if ("1".equals(flag)) {
            int a = 1 / 0;
        }
        stockApi.lockStock();
        return "success";
    }
}
